package com.zhuge_new.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhuge_new.Adapter.CardExamineAdapter;
import com.zhuge_new.Adapter.FragmentsAdapter;
import com.zhuge_new.Base.BaseActivity;
import com.zhuge_new.Dialog.PatmentDialog;
import com.zhuge_new.Fragment.CardFragment;
import com.zhuge_new.Fragment.CardFragment2;
import com.zhuge_new.R;
import com.zhuge_new.untils.ActivityStack;


import java.util.ArrayList;

/**
 * Created by lenovo on 2018-09-11.
 */

public class CardExamineActivity extends BaseActivity implements View.OnClickListener {

    private RecyclerView card_list;
    private CardExamineAdapter Adapter;
    private ArrayList<String> listbag = new ArrayList<String>();
    private ArrayList<Fragment> list=new ArrayList();
    private TextView ex_title;
    private ViewPager card_vp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cardexamine);

        init_title();
        listbag.add("信用卡包");
        listbag.add("储蓄卡包");
    }


    @Override
    public void init_title() {
        super.init_title();
        final ImageView ex_back = findViewById(R.id.ex_back);
        ex_title = findViewById(R.id.ex_title);
        card_vp = findViewById(R.id.card_vp);
        ImageView ex_join = findViewById(R.id.ex_join);
        ex_back.setOnClickListener(this);
        ex_title.setOnClickListener(this);
        ex_join.setOnClickListener(this);

        CardFragment cardFragment = new CardFragment();
        Bundle directManager = new Bundle();
        directManager.putString("grade", "1");
        cardFragment.setArguments(directManager);
        list.add(cardFragment);


        CardFragment2 cardFragment2 = new CardFragment2();
        Bundle cardMannger = new Bundle();
        cardMannger.putString("grade", "2");
        cardFragment2.setArguments(cardMannger);
        list.add(cardFragment2);

        FragmentsAdapter fragmentPagerAdapter=new FragmentsAdapter(getSupportFragmentManager(),list);
        card_vp.setAdapter(fragmentPagerAdapter);
        card_vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                if (position==0){
                    ex_title.setText("信用卡包");
                }else {
                    ex_title.setText("储蓄卡包");
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ex_back:
                ActivityStack.getScreenManager().popOneActivity(CardExamineActivity.class);
                break;
            case R.id.ex_title:
                title_top();
                break;
            case R.id.ex_join:
                Intent intent = new Intent(CardExamineActivity.this, CreditAddition1Activity.class);
                startActivity(intent);
                ActivityStack.getScreenManager().popOneActivity(CardExamineActivity.class);
                break;
        }
    }

    private void title_top() {
        PatmentDialog patmentDialog = new PatmentDialog(CardExamineActivity.this, listbag);
        patmentDialog.setTitle("请选择银行卡包");
        patmentDialog.setOnSelectedListener(new PatmentDialog.OnSelectedListener() {
            @Override
            public void getData(String data) {
                ex_title.setText(data);
                if (data.equals("信用卡包")) {
                    card_vp.setCurrentItem(0,false);
                } else {
                    card_vp.setCurrentItem(1,false);
                }
            }
        });
        patmentDialog.show();
    }


}
